<template>
<div>
  <h1 class="oneh1">音乐馆</h1>
  <div class="swiper-container">
    <div class="swiper-wrapper">

      <div class="swiper-slide" v-for="(item,i) in banner" :key="i">
        <img :src="item.picUrl" alt="">
      </div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
  </div>
</div>
</template>

<script>
import  Swiper from "../../node_modules/swiper/swiper-bundle";
export default {
name: "Index",

  data:()=>{
  return {
    banner:[]
  }
  },
  methods: {
    initSwiper(){
      this.swiper = new Swiper('.swiper-container',{
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay:{
          disableOnInteraction:false
        },
        observer: true,//修改swiper自己或子元素时，自动初始化swiper
        observeParents: true,//修改swiper的父元素时，自动初始化swiper
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
        },
      })
    }

  },
  created() {

  this.axios.get("/api/recommend/banner").then(data=>{
    console.log(data.data.data)
    this.banner=data.data.data
    this.$nextTick(()=>{
      this.initSwiper()

    })
  }).catch(err=>{
    console.log(err)
  })
  }
}
</script>

<style scoped>
.oneh1{
  display: block;
  margin: 0 auto;
  width: 196px;
  height: 40px;
  text-align: center;
}
.swiper-container {
  width: 750px;
  height: 300px;
  //background-color: blue;
}
.swiper-container img {
  //width: 100%;
  height: 100%;
//background-color: blue;
}
/deep/.swiper-button-prev{
//background-color: blue;
}
</style>